class Storage {
    getItem(key: string) {
        const value = window.localStorage.getItem(key)
        if(value) {
            try {
                return JSON.parse(value)
            } catch (error) {
                return value
            }
        }
    }

    setItem(key: string, value: any) {
        if(typeof value === 'object') {
            value = JSON.stringify(value)
        }
        window.localStorage.setItem(key, value)
    }

    removeItem(key: string) {
        window.localStorage.removeItem(key)
    }
}

export default new Storage()